;;==========================================================================
;; Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
;;==========================================================================

    INCLUDE kxarm.h
	AREA	|.text|, CODE , READONLY

    IMPORT memsetup
    IMPORT C_main

	EXPORT StartUp
StartUp
	b	reset
	b	die
	b	die
	b	die
	b	die
	b	die
	b	die
	b	die

reset
	mrs	r0, cpsr
	bic	r0, r0, #0x1f
	orr	r0, r0, #0x13
	msr	cpsr, r0

	; setup memory
	bl	memsetup

    ldr sp, =0xa0020000 ;buffer base addr
    bl  C_main

die
	b	die

;===================================================================
    MACRO
    GET_CLKCFG $retval


        ; read CLKCFG's value
        mrc p14, 0, $retval, c6, c0, 0


        ; mask out irrelevant bits
        and     $retval, $retval, #0xF

    MEND

    MACRO
    PUT_CLKCFG $writeval


        ; mask out irrelevant bits
        and     $writeval, $writeval, #0xF

        ; write CLKCFG's value
        mcr p14, 0, $writeval, c6, c0, 0

    MEND

    LEAF_ENTRY ReadCLKCFG
        GET_CLKCFG   r0
        mov pc, lr

    LEAF_ENTRY WriteCLKCFG
        PUT_CLKCFG   r0
        mov pc, lr


// EXTERN_C void fmemcpy(void * pDest, const void * pSource, unsigned long cb)
    EXPORT fmemcpy
fmemcpy
    cmp     r2, #0
    beq     %f1
    str     r4, [sp, #4]!

2   ldr     r4, [r1], #4
    sub     r2, r2, #4
    str     r4, [r0], #4
    cmp     r2, #4
    bge     %b2

    and     r2, r2, #0x3
    cmp     r2, #0
    beq     %f3
    ldrh    r4, [r1]
    strh    r4, [r2]

3   ldr     r4, [sp], #-4
1   mov     pc, lr

	END
